package com.superpai.api;

import org.codehaus.jackson.map.ObjectMapper;

import com.superpai.common.Constants;
import com.superpai.request.user.GetReceiverAddressListRequest;
import com.superpai.response.user.GetReceiverAddressListResponse;
import com.superpai.response.user.UserLoginResponse;
import com.superpai.utils.DefaultClient;
import com.superpai.utils.WebUtils;

/**
 * @author Devin.Hu
 * @date 2011-9-24
 * @version V1.0
 * @description 用户api
 */
public class UserAPI extends BaseAPI {

	/**
	 * 查询买家收货地址列表
	 * 
	 * @param buyerUin 用户QQ号码
	 * @return
	 * @throws Exception
	 */
	public GetReceiverAddressListResponse getReceiverAddressList(int buyerUin , String token) throws Exception{
		GetReceiverAddressListRequest req = new GetReceiverAddressListRequest();
		req.setBuyerUin(buyerUin);
		
		DefaultClient client = new DefaultClient(Constants.user_getReceiverAddressList);
		GetReceiverAddressListResponse response = client.execute(req);
		return response;
	}
	
	/**
	 * 用户登录
	 * 
	 * @param qq
	 * @param pwd
	 * @return
	 * @throws Exception
	 */
	public UserLoginResponse userLogin(String qq , String pwd) throws Exception{
		String rsp = WebUtils.doGet("http://pt.3g.qq.com/json/login3gonly.jsp?qq="+qq+"&pwd="+pwd+"");
		ObjectMapper objectMapper = new ObjectMapper();  
		return objectMapper.readValue(rsp, UserLoginResponse.class);
	}
}
